package com.sondon.mayi.adapter;

import java.util.ArrayList;
import java.util.List;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.sondon.mayi.entity.GoodInfo;

/**
 * @Project : Fruit
 * @Package : com.sondon.mayi.adapter
 * @Class : GoodsListAdapter
 * @Author : 蔡文锋
 * @DateTime：2015年6月10日 下午9:23:34
 * @Blog：http://blog.csdn.net/caiwenfeng_for_23
 * @Description : {}
 *
 */
@EBean
public class GoodsListAdapter extends BaseAdapter{
	@RootContext
	Context context;
	private List<GoodInfo> goods=new ArrayList<GoodInfo>();
	
	public void SetData(List<GoodInfo> goods){
		//清空原有数据
		this.goods.clear();
		if(goods!=null){
			this.goods=goods;
		}
		//更新
		this.notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		return this.goods.size();
	}

	@Override
	public Object getItem(int position) {
		return this.goods.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		GoodsList_Item item=null;
				if(convertView == null){
					item=GoodsList_Item_.build(context);
				}else{
					item=(GoodsList_Item) convertView;
				}
				item.bindData(this.goods.get(position));
		return item;
	}
}
